﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Smile.Converter
{
    public static class DateTimeConverter
    {
        public static DateTime FromUnixTimestamp(string timestamp)
        {
            return FromUnixTimestamp(Convert.ToDouble(timestamp));
        }

        public static DateTime FromUnixTimestamp(double timestamp)
        {
            var dateTime = new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime();
            return dateTime.AddSeconds(timestamp).ToLocalTime();
        }

        public static double ToUnixTimeStamp(DateTime dateTime)
        {
            TimeSpan span = (dateTime.ToLocalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
            return (long)span.TotalSeconds;
        }

        public static DateTime FromJavaTimestamp(string timestamp)
        {
            return FromJavaTimestamp(Convert.ToDouble(timestamp));
        }

        public static DateTime FromJavaTimestamp(double timestamp)
        {
            var dateTime = new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime();
            return dateTime.AddSeconds(Math.Round(timestamp / 1000)).ToLocalTime();
        }
    }
}
